<?php
require '../config.php';
require '../libs/class.login.php';

$log = new logmein();
$log->checklogin();

$mod = isset($_POST['mod']) ? strval($_POST['mod']) : NULL;
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;

switch ($mod){
	case 'category':
		$db->delete('categories', 'c_id = ' . $id);
	break;
	case 'games':
		// Get record
		$Qry = 'SELECT g_id, images
				FROM games
				WHERE g_id = ' . (int)$id;
		$row = $db->fetchAll($Qry);

		if ($row) {
			// Delete Image
			$img = $_SERVER['DOCUMENT_ROOT'] . '/data/uploads/' . $row[0]['images'];

			if (file_exists($img))
				unlink($img);

			// Delete record
			$db->delete('games', 'g_id = ' . $row[0]['g_id']);
		}
	break;
}